<?php

use console\db\Migration;

/**
 * 创建推荐数据相关信息表
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class m180201_103000_t_spread extends Migration {

    /**
     * {@inheritdoc}
     */
    public function up() {

        /**
         * 推荐内容表
         * @todo create table `spread`.
         */
        $this->tableBuilder([
            'name' => 'spread',
            'comment' => '推荐内容表',
            'columns' => [
                'id' => $this->primaryKey(),
                'user_id' => $this->integer(11)->unsigned()->notNull()->defaultValue(0)->comment('用户ID'),
                'title' => $this->string(50)->notNull()->comment('名称'),
                'description' => $this->string(100)->defaultValue('')->comment('描述'),
                'category' => $this->string(30)->defaultValue('')->comment('栏目'),
                'thumb' => $this->string(30)->defaultValue('')->comment('缩略图'),
                'model' => $this->char(20)->notNull()->defaultValue('')->comment('关联模型'),
                'model_id' => $this->integer(11)->notNull()->defaultValue(0)->comment('关联模型主键'),
                'created_at' => $this->unixTimestamp()->comment('创建时间'),
                'updated_at' => $this->unixTimestamp()->comment('更新时间'),
            ],
        ]);

        /**
         * 活动表
         * @todo create table `spread_activity`.
         */
        $this->tableBuilder([
            'name' => 'spread_activity',
            'comment' => '活动表',
            'columns' => [
                'id' => $this->primaryKey(),
                'name' => $this->string(50)->notNull()->comment('名称'),
                'thumb' => $this->char(255)->defaultValue('')->comment('缩略图'),
                'type_id' => $this->integer(11)->unsigned()->notNull()->defaultValue(0)->comment('类型ID'),
                'description' => $this->string(255)->defaultValue('')->comment('描述'),
                'begin_time' => $this->unixTimestamp()->comment('开始时间'),
                'end_time' => $this->unixTimestamp()->comment('结束时间'),
                'template' => $this->char(30)->defaultValue('')->comment('页面模板名称'),
                'recommend_at' => $this->unixTimestamp()->comment('推荐时间'),
                'status' => $this->tinyint(1)->notNull()->defaultValue(10)->comment('状态'),
                'created_at' => $this->unixTimestamp()->comment('获得时间'),
                'updated_at' => $this->unixTimestamp()->comment('更新时间'),
            ],
        ]);

        /**
         * 活动类型表
         * @todo create table `spread_type`.
         */
        $this->tableBuilder([
            'name' => 'spread_type',
            'comment' => '活动类型表',
            'columns' => [
                'id' => $this->primaryKey(),
                'name' => $this->string(50)->notNull()->comment('类型名称'),
                'label' => $this->char(50)->notNull()->comment('标识名'),
                'thumb' => $this->char(255)->defaultValue('')->comment('缩略图'),
                'description' => $this->string(255)->defaultValue('')->comment('描述'),
                'status' => $this->tinyint(1)->notNull()->defaultValue(10)->comment('状态'),
                'created_at' => $this->unixTimestamp()->comment('获得时间'),
                'updated_at' => $this->unixTimestamp()->comment('更新时间'),
                'deleted_at' => $this->unixTimestamp()->comment('删除时间'),
            ],
        ]);
    }

    /**
     * {@inheritdoc}
     */
    public function down() {
        $this->dropTable('{{%spread_type}}');
        $this->dropTable('{{%spread_activity}}');
        $this->dropTable('{{%spread}}');
    }

}
